package com.hx.vending.service.impl;

import com.hx.vending.bean.OnlineOrder;
import com.hx.vending.bean.Problem;
import com.hx.vending.dao.CustomerMapper;
import com.hx.vending.dao.OnlineOrderMapper;
import com.hx.vending.dao.ProblemMapper;
import com.hx.vending.service.IProblemService;
import com.hx.vending.util.DateUtil;
import com.hx.vending.util.Msg;
import com.hx.vending.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/1/25.
 */
@Service
public class ProblemServiceImpl implements IProblemService {

    @Autowired
    private ProblemMapper problemMapper;
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public Msg insertProblem(Problem problem) {
        if(ToolUtil.isEmpty(problem.getProblemOrderId())){
            return Msg.fail().add("msg","订单不能为空");
        }
        Map<String,Object> map = customerMapper.selectByOrderId(problem.getProblemOrderId());
        problem.setProblemUserId(Integer.parseInt(map.get("userId").toString()));
        problem.setProblemCustomerId(Integer.parseInt(map.get("customerId").toString()));
        problem.setProblemEquipmentId(map.get("equipmentId").toString());
        problem.setProblemTime(DateUtil.getTime());
        //状态 1已解决 2未解决
        problem.setProblemState(2);
        int i = problemMapper.insertSelective(problem);
        if(i > 0){
            return Msg.success();
        }
        return Msg.fail();
    }

    @Override
    public List<Problem> selectByCondition(Integer userId) {
        return problemMapper.selectByCondition(userId);
    }
}
